package com.cblz.bd.server.core.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cblz.bd.common.core.entity.BaAdminLog;
import com.cblz.bd.common.core.entity.system.QueryRequest;
import com.cblz.bd.server.core.mapper.BaAdminLogMapper;
import com.cblz.bd.server.core.service.BaAdminLogService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

/**
 * @author yanjieping
 * @description 针对表【ba_admin_log(管理员日志表)】的数据库操作Service实现
 * @createDate 2022-11-04 15:09:53
 */
@Slf4j
@Service("baAdminLogService")
@RequiredArgsConstructor
public class BaAdminLogServiceImpl extends ServiceImpl<BaAdminLogMapper, BaAdminLog>
        implements BaAdminLogService {

    @Override
    public IPage<BaAdminLog> getAllLog(BaAdminLog baAdminLog, QueryRequest queryRequest) {
        LambdaQueryWrapper<BaAdminLog> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        if (null != baAdminLog.getId()) {
            lambdaQueryWrapper.eq(BaAdminLog::getId, baAdminLog.getId());
        }
        if (null != baAdminLog.getAdminId()) {
            lambdaQueryWrapper.eq(BaAdminLog::getAdminId, baAdminLog.getAdminId());
        }
        if (StringUtils.isNotBlank(baAdminLog.getUsername())) {
            lambdaQueryWrapper.like(BaAdminLog::getUsername, baAdminLog.getUsername());
        }
        if (StringUtils.isNotBlank(baAdminLog.getUrl())) {
            lambdaQueryWrapper.like(BaAdminLog::getUrl, baAdminLog.getUrl());
        }
        if (StringUtils.isNotBlank(baAdminLog.getTitle())) {
            lambdaQueryWrapper.like(BaAdminLog::getTitle, baAdminLog.getTitle());
        }
        if (StringUtils.isNotBlank(baAdminLog.getData())) {
            lambdaQueryWrapper.like(BaAdminLog::getData, baAdminLog.getData());
        }
        if (StringUtils.isNotBlank(baAdminLog.getIp())) {
            lambdaQueryWrapper.like(BaAdminLog::getIp, baAdminLog.getIp());
        }
        if (StringUtils.isNotBlank(baAdminLog.getUseragent())) {
            lambdaQueryWrapper.like(BaAdminLog::getUseragent, baAdminLog.getUseragent());
        }
        if (null != baAdminLog.getCreatetimeStartTime()) {
            lambdaQueryWrapper.ge(BaAdminLog::getCreatetime, baAdminLog.getCreatetimeStartTime());
        }
        if (null != baAdminLog.getCreatetimeEndTime()) {
            lambdaQueryWrapper.le(BaAdminLog::getCreatetime, baAdminLog.getCreatetimeEndTime());
        }

        return baseMapper.selectPage(new Page<>(queryRequest.getPageNum(), queryRequest.getPageSize()), lambdaQueryWrapper.orderByDesc(BaAdminLog::getCreatetime));
    }
}




